unit Render.V8.Handler.Manager;

interface
uses
  Winapi.Windows, System.SysUtils, System.Classes, System.Generics.Collections, uCEFv8Handler, uCEFInterfaces, uCEFConstants,
  uCEFv8Value, Render.V8.Handler;

type
  TRenderHandlerMgr = class(TDictionary<string, TCustomV8Handler>)
  private
    class var
      FInstance: TRenderHandlerMgr;

  public
    function AddHandler(handlerName: string; handler: TCustomV8Handler): Boolean;
  public
    class function GetInstance: TRenderHandlerMgr;
  end;

implementation

{ TRenderHandlerMgr }

function TRenderHandlerMgr.AddHandler(handlerName: string; handler: TCustomV8Handler): Boolean;
begin
  if not ContainsKey(handlerName) then
  begin
    Add(handlerName, handler);
    Result := True;
  end;
end;

class function TRenderHandlerMgr.GetInstance: TRenderHandlerMgr;
begin
  if FInstance = nil then
    FInstance := TRenderHandlerMgr.Create();
  Result := FInstance;
end;

initialization
finalization
  FreeAndNil(TRenderHandlerMgr.FInstance);

end.
